/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"


INT16 _main( char FARTYPE *ops )
{
    return eyelink_send_message( ops );
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    INT16 code;
    char FARTYPE *elb;
    double *status;
    mwSize td[] = {1,1};
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( mxIsChar(*prhs) != 1)
      mexErrMsgTxt( "msg must be a string.");
      
    elb  = mxArrayToString(*prhs);
    
    if(elb == NULL) 
      mexErrMsgTxt("Could not convert input to string.");
   
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
 
    *status = (double ) _main( elb );    
    mxFree( elb );    
    return;
}


